
<html>
<head>
	<meta charset="UTF-8">
	<title>字段信息修改</title>
	<link href="../../static/easyui/themes/bootstrap/easyui.css" rel="stylesheet" type="text/css"/>
	<link href="../../static/easyui/themes/icon.css" rel="stylesheet" type="text/css"/>
	<link href="../../static/css/esaas-easyui-add.css" rel="stylesheet" type="text/css"/>
	<script src="../../static/easyui/jquery.min.js" type="text/javascript"></script>
	<script src="../../static/easyui/jquery.easyui.min.js" type="text/javascript" charset="utf-8"></script>
	<script src="../../static/easyui/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
	<script src="../../static/plugin/assets/jslib.util.js" type="text/javascript"></script>
	<script src="../../static/plugin/assets/jslib.jquery.ajax.js" type="text/javascript"></script>
	<script src="../../static/plugin/assets/jslib.easyui.util.js" type="text/javascript"></script>
	<script src="../../ffres/dict/all.js"></script>
	<a href="" target="_blank" id="commonLink" name="commonLink"></a>
</head>
<body class="easyui-layout">
<form id="ff" method="post">
	<div class="esaas-info-title">字段信息</div>
	<table class="esaas-info-add-table">
		<tr>
			<td width="15%" align="right">字段代码：</td>
			<td width="35%">
				<input class="easyui-textbox" type="text" name="fieldCode" id="fieldCode" data-options="required:true" style="width:70%;height:25px;"/>
				<input type="hidden" name="fieldId" id="fieldId"/>
				<input type="hidden" name="itemId" id="itemId"/>
				<input type="hidden" name="dictId" id="dictId"/>
				<input type="hidden" name="objectId" id="objectId"/>
				<a href="javascript:void(0)" class="easyui-linkbutton" onclick="choiceWord()">&nbsp;选&nbsp;择&nbsp;</a>
			</td>
			<td width="15%" align="right">字段名称：</td>
			<td width="35%">
				<input class="easyui-textbox" type="text" name="fieldName" id="fieldName" data-options="required:true" style="width:100%;height:25px;"></input>
			</td>
		</tr>
		<tr>
			<td width="25%" align="right">字段设置：</td>
			<td width="35%"><input type="checkbox" name="isPk" id="isPk" data-options="required:true">主键</input>
				&nbsp;&nbsp;
				<input type="checkbox" name="isAllowNull" id="isAllowNull" data-options="required:true">允许为空</input></td>

			<td></td>
			<td></td>
		</tr>
		<tr>
			<td width="15%" align="right" valign="top">字段描述：</td>
			<td colspan="3"><textarea name="fieldDesc" id="fieldDesc" class="easyui-validatebox" style="overflow-x:hidden;height:60px;width:98%;"></textarea></td>

			<td></td>
			<td></td>
		</tr>
		<tr>
			<td width="15%" align="right">字段类型：</td>
			<td width="35%"><select class="easyui-combobox" id="fieldType" name="fieldType" style="width:100%;height:25px;" data-options="required:true,editable:false,valueField:'enname',textField:'cnname',data:PUB_DATA_TYPE"></select></td>
			<td width="15%"></td>
			<td width="35%"></td>
		</tr>
		<tr>
			<td width="15%" align="right">字段长度：</td>
			<td><input class="easyui-textbox" type="text" id="fieldLength" name="fieldLength" style="width:100%;height:25px;"></input></td>
			<td width="15%" align="right">字段精度：</td>
			<td><input class="easyui-numberbox" type="text" id="fieldPrecision" name="fieldPrecision" style="width:100%;height:25px;" value="0"></input></td>
		</tr>
		<tr>
			<td width="15%" align="right">字段选项：</td>
			<td>
				<input class="easyui-textbox" id="fieldOption" name="fieldOption" readOnly style="width:70%;height:25px;"/>
				<a href="javascript:void(0)" class="easyui-linkbutton" onclick="choiceDictOption()">&nbsp;选&nbsp;择&nbsp;</a>
			</td>
			<td></td>
			<td></td>
		</tr>
	</table>
</form>
<div style="text-align:center;padding:50px">
	<a href="javascript:void(0)" class="easyui-linkbutton" onclick="submitForm()">&nbsp;&nbsp;保&nbsp;&nbsp;存&nbsp;&nbsp;</a>
	<a href="javascript:void(0)" class="easyui-linkbutton" onclick="closeForm()">&nbsp;&nbsp;关&nbsp;&nbsp;闭&nbsp;&nbsp;</a>
</div>

<script>
	$(function() {
		var fieldId = $.getUrlParam('fieldId');
		$.restfulGet('../../api/model/table/field/' + fieldId,null,function(data){
			$.restfulGet('../../api/dict/item/info/' + data.rows.itemId, null,function(itemData){
				data.rows.fieldType = itemData.rows.itemDataType
				$('#ff').form('load', {
					fieldId : data.rows.fieldId,
					fieldCode : data.rows.fieldCode,
					fieldName : data.rows.fieldName,
					fieldDesc : data.rows.fieldDesc,
					fieldType : data.rows.fieldType,
					fieldLength : data.rows.fieldLength,
					fieldPrecision : data.rows.fieldPrecision,
					fieldOption : data.rows.fieldOption,
					fieldId : data.rows.fieldId,
					itemId : data.rows.itemId,
					dictId : data.rows.dictId,
					objectId : data.rows.objectId,
				});
			});

			$('#isPk').prop("checked", data.rows.isPk == "Y");
			$('#isAllowNull').prop("checked", data.rows.isAllowNull == "Y");
			if (data.rows.isPk == "Y") {
				$('#isAllowNull').attr("disabled", true);
			}
		});

		$('#isPk').change(
				function isPkChange(event){
					if ($('#isPk').prop("checked")) {
						$('#isAllowNull').prop("checked", false);
						$('#isAllowNull').attr("disabled", true);
					} else {
						$('#isAllowNull').prop("checked", false);
						$('#isAllowNull').attr("disabled", false);
					}

				}
		);
	});

	function choiceWord(){
		JLEUtil.createModalWin('', 'CompositWord.html');
	}

	function returnChoiceWord(code,name){
		$("#fieldCode").textbox('setValue',code);
		$("#fieldName").textbox('setValue',name);
		JLEUtil.closewin();
	}

	function choiceDictOption(){
		JLEUtil.createModalWin('', 'ChoiceDictOption.html?callBack=doFinishOptionChoice');
	}

	function doFinishOptionChoice(dictId,dictCode){
		$("#fieldOption").textbox('setValue',dictCode);
		$("#dictId").textbox('setValue',dictId);
		JLEUtil.closewin();
	}


	function submitForm() {
		if (!$('#ff').form('validate'))
			return;
		var jsonData = $("#ff").serializeJson();
		jsonData.isAllowNull = $('#isAllowNull').prop("checked") ? "on" : "";
		$.restfulPut('../../api/model/table/field/item', jsonData, function(data) {
			window.parent.reloadList();
		});
	};

	function closeForm() {
		window.parent.JLEUtil.closewin();
	}
</script>
</body>
</html>
